package com.sskj.cndragon.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.constraint.Group;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sskj.cndragon.R;
import com.sskj.cndragon.bean.PayWayBean;
import com.sskj.cndragon.view.ToolBarLayout;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/05/24
 */
public class ReceiptActivity extends BaseActivity<ReceiptPresenter> {

    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.tv_weixin)
    TextView tvWeixin;
    @BindView(R.id.iv_wx_lock)
    ImageView ivWxLock;
    @BindView(R.id.iv_wx_edit)
    ImageView ivWxEdit;
    @BindView(R.id.iv_wx_set)
    ImageView ivWxSet;
    @BindView(R.id.group_wx)
    Group groupWx;
    @BindView(R.id.tv_zhifubao)
    TextView tvZhifubao;
    @BindView(R.id.iv_ali_lock)
    ImageView ivAliLock;
    @BindView(R.id.iv_ali_edit)
    ImageView ivAliEdit;
    @BindView(R.id.iv_ali_set)
    ImageView ivAliSet;
    @BindView(R.id.group_ali)
    Group groupAli;

    private boolean weStatus;
    private boolean aliStatus;

    @Override
    public ReceiptPresenter getPresenter() {
        return new ReceiptPresenter();
    }

    @Override
    public void initView() {
        toolbar.setTitle(App.INSTANCE.getString(R.string.shoukuanfangshi));
        toolbar.setLeftButtonOnClickListener(view -> finish());

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.app_activity_receipt;
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.getPayWay();
    }

    @Override
    public void initData() {
        mPresenter.getPayWay();

        ClickUtil.click(300, ivWxSet, () -> {
            AddReceiptActivityActivity.start(ReceiptActivity.this, Constans.WECHAT);
        });
        ClickUtil.click(300, ivAliSet, () -> {
            AddReceiptActivityActivity.start(ReceiptActivity.this, Constans.ALIPAY);
        });
        ClickUtil.click(300, ivWxLock, () -> {
            mPresenter.changeLock(Constans.WECHAT, weStatus ? "0" : "1");
        });
        ClickUtil.click(300, ivAliLock, () -> {
            mPresenter.changeLock(Constans.ALIPAY, aliStatus ? "0" : "1");
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, ReceiptActivity.class);
        context.startActivity(intent);
    }

    public void getPayWayOK(PayWayBean data) {
        if (data == null) {
            return;
        }
        if (isEmpty(data.getWechatAccount())) {
            groupWx.setVisibility(View.GONE);
            ivWxSet.setVisibility(View.VISIBLE);
        } else {
            weStatus = data.isWechatStatus();
            groupWx.setVisibility(View.VISIBLE);
            ivWxSet.setVisibility(View.GONE);
            tvWeixin.setText(data.getWechatAccount());
            if (data.isWechatStatus()) {
                ivWxLock.setImageResource(R.mipmap.icon_jiesuo);
            } else if (!data.isWechatStatus()) {
                ivWxLock.setImageResource(R.mipmap.icon_suoding);
            }
        }
        if (isEmpty(data.getZhifubaoAccount())) {
            groupAli.setVisibility(View.GONE);
            ivAliSet.setVisibility(View.VISIBLE);
        } else {
            aliStatus = data.isZhifubaoStatus();
            groupAli.setVisibility(View.VISIBLE);
            ivAliSet.setVisibility(View.GONE);
            tvZhifubao.setText(data.getZhifubaoAccount());
            if (data.isZhifubaoStatus()) {
                ivAliLock.setImageResource(R.mipmap.icon_jiesuo);
            } else if (!data.isZhifubaoStatus()) {
                ivAliLock.setImageResource(R.mipmap.icon_suoding);
            }
        }
        ClickUtil.click(300, ivWxEdit, () -> {
            AddReceiptActivityActivity.start(ReceiptActivity.this, Constans.WECHAT, data.getWechatAccount(), data.getWechatUrl());

        });
        ClickUtil.click(300, ivAliEdit, () -> {
            AddReceiptActivityActivity.start(ReceiptActivity.this, Constans.ALIPAY, data.getZhifubaoAccount(), data.getZhifubaoUrl());
        });
    }
}
